var t = require("../../../@babel/runtime/helpers/toConsumableArray"), a = getApp();

Page({
    data: {
        showExplainPopup: !1,
        goodsList: [],
        searchGoodsList: null,
        sets: null,
        loading: !1,
        isMoreData: !0,
        page: 1,
        searchInputKeyword: "",
        is_retail: !1
    },
    onLoad: function(t) {
        "retail" == t.target ? (wx.setNavigationBarTitle({
            title: "零售"
        }), this.setData({
            is_retail: !0
        })) : (wx.setNavigationBarTitle({
            title: "订货"
        }), this.setData({
            is_retail: !1
        })), this.getGoods();
    },
    onShareAppMessage: function() {},
    onShareTimeline: function() {},
    onReachBottom: function() {
        this.getGoods();
    },
    displayExplainPopup: function() {
        this.setData({
            showExplainPopup: !0
        });
    },
    closeExplainPopup: function() {
        this.setData({
            showExplainPopup: !1
        });
    },
    viewGoods: function(t) {
        var a = "/packageA/detail_v2/detail_v2?id=" + t.target.dataset.id;
        this.data.is_retail ? a += "&fromStock=2" : a += "&fromStock=1", wx.navigateTo({
            url: a
        });
    },
    getGoods: function() {
        var e = this;
        if (!0 !== this.data.loading && !1 !== this.data.isMoreData) {
            wx.showLoading({
                title: "加载中",
                mask: !0
            }), this.setData({
                loading: !0
            });
            var i = a.getNetAddresss("plugin.agency.api.goods.goods-list");
            i += "&page=" + this.data.page, i += "&is_retail=" + this.data.is_retail, a._postNetWork({
                url: i,
                success: function(a) {
                    var i = a.data, s = i.data, o = i.result, n = i.msg;
                    if (0 === o) return wx.hideLoading(), void wx.showToast({
                        title: n,
                        success: function(t) {
                            wx.redirectTo({
                                url: "/packageG/member_v2/member_v2"
                            });
                        }
                    });
                    var r = {};
                    null === e.data.sets && (r.sets = s.set), (s.current_page === s.last_page || 0 === s.data.length || s.data.length < s.per_page) && (r.isMoreData = !1);
                    var d = e.data.goodsList;
                    d.push.apply(d, t(s.data)), r.goodsList = d, r.page = e.data.page + 1, r.loading = !1, 
                    e.setData(r), wx.hideLoading();
                }
            });
        }
    },
    searchGoods: function(t) {
        var a = t.detail, e = this.data.goodsList.filter(function(t) {
            return -1 !== t.title.indexOf(a);
        });
        this.setData({
            searchGoodsList: e
        });
    },
    cancelSearch: function() {
        this.setData({
            searchGoodsList: null
        });
    }
});